
"""
@Desc    :   动态加载插件类
"""
import importlib
import logging

from src.enum.task import CrawlerTypeEnum
from src.exception import NonPluginException
from .awb import AwbSpiderBase
from .obl import OblSpiderBase

def load_plugin_class(plugin_type:CrawlerTypeEnum,uni_code:str,class_name:str):
    try:
        if plugin_type == CrawlerTypeEnum.AIR_WAYBILL:
            plugin_module = importlib.import_module("plugins.awb." + uni_code.lower())
        elif plugin_type == CrawlerTypeEnum.OCEAN_WAYBILL:
            plugin_module = importlib.import_module("plugins.obl." + uni_code.lower())
        else:
            raise NonPluginException()
        module_class = getattr(plugin_module, class_name)
        return module_class()
    except (ModuleNotFoundError, AttributeError) as e:
        logging.error(e)
        raise NonPluginException()


